//
//  JXCartController.m
//  JiaoX
//
//  Created by jiaoxiu－005 on 15/1/12.
//  Copyright (c) 2015年 北京娇羞科技有限公司. All rights reserved.
//

#import "JXCartController.h"
#import "JXBaseRequest.h"
#import "CartDataTool.h"
#import "MJRefresh.h"
#import "CartInfoDao.h"
#import "JXCartInfoCell.h"
#import "CartProdSub.h"
#import "UserDefaultsHelper.h"
#import "ConfigConstants.h"
#import "UIImageView+WebCache.h"
#import "CartNullView.h"
#import "CartButtonPriceBar.h"
#import "CalcView.h"
#import "JXNavigationController.h"
#import "JXLoginRegistCheckController.h"
#import "JXAccountCenterController.h"
#import "CartOrderStatusController.h"
#import "JXOrderViewController.h"
#import "JXProdDetailCtl.h"

#define ISOUTLISTALERT -1

@interface JXCartController ()<UITableViewDelegate,UITableViewDataSource,CartNullViewDelegate,CartButtonPriceBarDelegate,CalcViewDelegate,UIAlertViewDelegate,AccountCenterDelegate,CartOrderStatusDelegate,CartProdItemViewDelegate>
{
    //购物车数组(存放购物车所有商品)
    NSMutableArray *_cartInfos;
    //购物车数据库dao
    CartInfoDao *_cartInfoDao;
    //alert
    UIAlertView *_alert;
    //过期商品存储
    NSMutableArray*_prodIds;
    //结算中心需要的数据
    AddressAndCheckProdInfo * _accountInfo;
}

@property(nonatomic,assign)BOOL isHideTip;
@property(nonatomic,strong)UIImageView *tipBtn;
@property(nonatomic,copy)NSString *tipAdImage;
@property(nonatomic,copy)NSString *tipAdUrl;

@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)CartNullView *nullView;
@property(nonatomic,strong)CartButtonPriceBar *priceBar;
@property(nonatomic,assign)BOOL isDeleteProd;

@end

@implementation JXCartController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    _cartInfos = [NSMutableArray array];
    _cartInfoDao = [[CartInfoDao alloc]init];
    _prodIds = [NSMutableArray array];
    //初始化tabView
    [self setupTabView];
    //初始化广告位
    [self setUpTipView];
    //初始化空页面
    [self setupNullView];
    //初始化价格显示条
    [self setupPriceBar];
}

/**
 *  初始化tabView
 */
- (void)setupTabView
{
    _tableView = [[UITableView alloc]init];
    _tableView.frame = CGRectMake(0, 0, JXScreenW, JXScreenH);
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.backgroundColor =[UIColor whiteColor];
    _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLineEtched;
    [self.view addSubview:_tableView];
    //添加下拉刷新头
    [_tableView addHeaderWithTarget:self action:@selector(headerRereshing)];
    //处理商品较少后面多余分割线
    [_tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectMake(0, 0, JXScreenW, 49)]];
    [_tableView setHidden:YES];
}

/**
 *  初始化空页面
 */
- (void)setupNullView
{
    _nullView = [[CartNullView alloc]init];
    _nullView.x = (JXScreenW-_nullView.width)/2;
    _nullView.y = (JXScreenH-_nullView.height)/2;
    _nullView.delegate = self;
    [_nullView setHidden:YES];
    [self.view addSubview:_nullView];
}

/**
 *  初始化顶部广告位
 */
- (void)setUpTipView{
    _tipBtn = [[UIImageView alloc]initWithFrame:CGRectMake(0, NavHeight, JXScreenW, JXScreenW*0.125)];
    UIButton *btn = [[UIButton alloc]init];
    [btn setSize:CGSizeMake(SCALEX(19), SCALEX(19))];
    [btn setBackgroundImage:[UIImage imageNamed:@"ic_close"] forState:UIControlStateNormal];
    [btn setY:(_tipBtn.height-btn.height)/2];
    [btn setX:JXScreenW-10-btn.width];
    [btn addTarget:self action:@selector(setHideTipAp) forControlEvents:UIControlEventTouchUpInside];
    
    [_tipBtn addSubview:btn];
    _tipBtn.userInteractionEnabled = YES;
    UITapGestureRecognizer *singleTap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickTipAd)];
    [_tipBtn addGestureRecognizer:singleTap1];
    
    [self.view addSubview:_tipBtn];
}

/**
 *  初始化商品总价显示条
 */
-(void)setupPriceBar
{
    _priceBar = [[CartButtonPriceBar alloc]init];
    _priceBar.x = 0;
    _priceBar.y = JXScreenH - 49*2;
    _priceBar.delegate = self;
    [_priceBar setHidden:YES];
    [self.view addSubview:_priceBar];
}

/**
 * 刷新中状态
 */
-(void)headerRereshing
{
    //查询服务器数据覆盖本地数据库
    [self updateServerCartInfoToDB];
}


-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    // 界面可见时重新填充数据
    [self headerRereshing];
}


-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    // 在界面不可见的时候把数据库商品ID，商品数量提交给服务器
    [self commitToServerCartInfo];
}

/**
 *  把本地数据库数据提交给服务器
 *
 *  @return 提交是否成功
 */
-(void)commitToServerCartInfo
{
    if(![Utils isBlankString:TOKEN]){//非登录状态不提交到服务器
        //提交购物车数据到服务器
        [CartDataTool postCartProdsWithParam:[self getCommitParams] success:^(CartInfo *result) {
            if([Utils isBlankString:result.data]){
                JXLog(@"购物车数据提交成功");
            }else{
                JXLog(@"购物车数据提交失败");
            }
        } failure:^(NSError *error) {
        }];
    }
}

/**
 *  将字典或者数组转化为JSON串
 *
 *  @param theData 字典 or NSArray
 *
 *  @return NSData
 */
- (NSData *)dicWithArrayToData:(id)theData
{
    
    NSError *error = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:theData
                                                       options:NSJSONWritingPrettyPrinted
                                                         error:&error];
    
    if ([jsonData length] > 0 && error == nil){
        return jsonData;
    }else{
        return nil;
    }
}

/**
 *  查询服务器购物车数据覆盖到本地数据库
 */
-(void) updateServerCartInfoToDB
{
    if([Utils isBlankString:TOKEN]){//非登录状态查询数据库
        [self refreshComplete];
        [self queryDBFillData];
    }else{//如果是登录状态，请求服务器数据更新购物车数据库
        [CartDataTool cartInfoWithParam:nil success:^(CartInfo *result) {
            //结束刷新
            [self refreshComplete];
            //数据获取完毕
            if([Utils isBlankString:result.data]){
                self.tipAdImage = result.tipAdImage;
                self.tipAdUrl = result.tipAdUrl;
                [self showTipAd];
                //加载成功,存入到数据库
                [self updateLocalCartInfosToDB:result.prodList];
            }else{
                //加载服务器失败,尝试本地数据库
                [self queryDBFillData];
            }
        } failure:^(NSError *error) {
            //结束刷新
            [self refreshComplete];
            //加载网络失败，尝试本地数据库
            [self queryDBFillData];
        }];
    }
}

/**
 *  根据购物车模型数组 转成 购物车frame模型数据
 *
 *  @param prods 购物车模型数组
 *
 */
- (NSArray *)cartInfosFramesWithCartInfos:(NSArray *)prods
{
    NSMutableArray *frames = [NSMutableArray array];
    for (CartProdSub *prod in prods) {
        JXCartInfoFrame *frame = [[JXCartInfoFrame alloc] init];
        // 传递购物车商品模型数据，计算所有子控件的frame
        frame.infos = prod;
        [frames addObject:frame];
    }
    return frames;
}

/**
 *  把已购商品列表数据插入数据库
 *
 *  @param cartInfos 已购商品列表数据
 */
-(void)updateLocalCartInfosToDB:(NSArray *)cartInfos
{
    if(cartInfos.count){
        //覆盖更新之前先清空，再添加
        [_cartInfoDao deleteAllProds];
        //循环插入
        for(int i=0;i<cartInfos.count;i++){
            NSString *prodId  = [cartInfos[i] prodId];
            NSDictionary *cartProd = [cartInfos[i] keyValues];
            [_cartInfoDao addProd:prodId cartProd:cartProd];
        }
    }
    [self queryDBFillData];
}

/**
 *  查询数据库填充
 */
-(void)queryDBFillData
{
    NSArray *infos = [_cartInfoDao findAllProds];
    if(infos.count){
        //1.从数据库查询出数据
        [_cartInfos removeAllObjects];
        //显示tabview页面
        [self showTabView];
        // 2.获得最新的购物车frame数组
        NSArray *newFrames = [self cartInfosFramesWithCartInfos:infos];
        [_cartInfos addObjectsFromArray:newFrames];
        // 3.刷新tableView数据
        [self.tableView reloadData];
        // 4.TODO 重新计算购物车所有商品价格
        [self calculatorAccount:infos];
    }else{//没有数据,显示空白页面
        [self showNullView];
    }
    //刷新购物车数量角标
    [self getUnreadCount2];
}
/**
 *  计算总价格和节省的价格
 */
-(void)calculatorAccount:(NSArray *)cartInfos
{
    
    double spare = 0.0;
    double countNewPrice = 0.0;
    double countOldPrice = 0.0;
    
    for (int i = 0; i < cartInfos.count; i++) {
        double prodNewPrice;
        ProdPromotion *prodPromotion = [cartInfos[i] prodPromotion];
        if(prodPromotion){// 有买赠活动
            if(![Utils isBlankString:[prodPromotion price]]){// 有抢购价，取抢购价计算
                prodNewPrice = [[prodPromotion price] doubleValue];
            }else{// 无抢购价,取商品现价计算
                prodNewPrice = [[cartInfos[i] prodNewPrice] doubleValue];
            }
        }else{//无买赠活动
            prodNewPrice = [[cartInfos[i] prodNewPrice] doubleValue];
        }
        
        double prodOldPrice = [[cartInfos[i] prodOldPrice] doubleValue];
        NSInteger prodCount = [[cartInfos[i] prodCount] integerValue];
        countNewPrice = countNewPrice + (prodNewPrice * prodCount);
        countOldPrice = countOldPrice + (prodOldPrice * prodCount);
        spare = countOldPrice - countNewPrice;
    }
    [_priceBar setPriceNum:countNewPrice];
    [_priceBar setSpareNum:spare];
}

-(void)setHideTipAp{
    self.isHideTip = YES;
    [_tipBtn setHidden:YES];
    [_tableView setY:0];
    [_tableView setHeight:JXScreenH];
}

-(void)clickTipAd{
    [Utils dealUrlWithController:self url:self.tipAdUrl title:@"" fromWebView:NO];
}

-(void)showTipAd{
    if (!self.isHideTip) {
        //显示广告图
        if (self.tipAdUrl) {
            [_tipBtn setHidden:NO];
            [_tipBtn sd_setImageWithURL:[NSURL URLWithString:self.tipAdImage]];
            [_tableView setY:_tipBtn.height];
            [_tableView setHeight:self.view.height-_tableView.y];
            return;
        }
    }
    //隐藏广告图
    [_tipBtn setHidden:YES];
    [_tableView setY:0];
    [_tableView setHeight:JXScreenH];
}

/**
 *  显示tabview页面
 */
-(void)showTabView
{
    [_tableView setHidden:NO];
    [_priceBar setHidden:NO];
    [_nullView setHidden:YES];
}

/**
 *  显示空白页面
 */
-(void)showNullView
{
    [_tableView setHidden:YES];
    [_priceBar setHidden:YES];
    [_nullView setHidden:NO];
}

/**
 *  修改购物车count
 */
- (void)getUnreadCount2
{
    // 1.获取购物车商品数
    NSInteger prodNum = [_cartInfoDao queryProdsCount];
    // 2.显示购物车数量角标
    if (prodNum == 0) {
        self.tabBarItem.badgeValue = nil;
        [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
    } else {
        self.tabBarItem.badgeValue = [NSString stringWithFormat:@"%ld", (long)prodNum];
        [UIApplication sharedApplication].applicationIconBadgeNumber = prodNum;
    }
    JXLog(@"购物车商品数量--%ld",(long)prodNum);
}

/**
 *  当cell数据改变的时候回调
 *
 *  @param oldNum   原来数量
 *  @param newNum   要改变的数量
 *  @param position 点击的cell的位置
 *  @param calcView 计算器对象
 */
-(void)numChange:(NSUInteger)oldNum newNum:(NSUInteger)newNum position:(NSUInteger)position calcView:(id)calcView
{
    JXLog(@"oldNum:%lu ,newNum:%lu,position:%lu",(unsigned long)oldNum,(unsigned long)newNum,(unsigned long)position);
    CalcView *view = ((CalcView *)calcView);
    if(newNum == 0){// 数量为0时提示是否删除
        //判断是否删除该商品
        [self assertDeleteProd:view position:position];
        return;
    }else if([[_cartInfos[position] infos]prodNewPrice]==0 && newNum>1){// 如果是零元商品，只允许一件
        [view setNum:1];
        [DialogUtils showTipsWithView:self.view String:@"0元商品限1件"];
        return;
    }else if (newNum > 20) {// 单品最多20件
        [view setNum:20];
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"商品个数不能超过20个" message:@"" delegate: self cancelButtonTitle:nil otherButtonTitles:@"确定",nil];
        [alert show]; //显示删除对话框
        return;
    }else if([[_cartInfos[position] infos]prodPromotion]){// 判断商品是否活动限购，不允许超过限购数量
        if([[[_cartInfos[position] infos]prodPromotion] limitCount]>0){
            int limitCount = [[[_cartInfos[position] infos]prodPromotion] limitCount];
            if(newNum>limitCount){
                [view setNum:limitCount];
                [DialogUtils showTipsWithView:self.view String:[NSString stringWithFormat:@"抢购品限购%d件",limitCount]];
                return;
            }
        }
    }
    // 实时更新条目商品的数量
    [[_cartInfos[position] infos] setProdCount:[NSString stringWithFormat:@"%lu",(unsigned long)newNum]];
    //更新数据库该商品信息
    [_cartInfoDao updateProd:[[_cartInfos[position]infos] prodId] cartProd:[_cartInfos[position] infos].keyValues];
    //计算价格
    [self calculatorAccount: [_cartInfoDao findAllProds]];
    //刷新购物车数量角标
    [self getUnreadCount2];
}

/**
 *  判断是否删除商品
 */
-(void)assertDeleteProd:(CalcView *)calcView position:(NSUInteger)position
{
    _alert = nil;//每次都创建新的alert,并指定tag
    _alert = [[UIAlertView alloc]initWithTitle:@"确认删除商品?" message:@"" delegate: self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
    [_alert setTag:position];
    _alert.delegate = self;
    [_alert show]; //显示删除对话框
}

//当AlertView的隐藏动画结束的时候进行回调
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {
        if([alertView tag] == ISOUTLISTALERT){//删除过期商品
            if(_prodIds){
                //把过期商品的数量修改为零
                NSArray *prodArr =  [_cartInfoDao findAllProds];
                for (CartProdSub* prodSub in prodArr) {
                    for (NSString *prodId in _prodIds) {
                        BOOL isEq  = prodId.longLongValue == prodSub.prodId.longLongValue;
                        if(isEq){
                            [prodSub setProdCount:@"0"];
                            [_cartInfoDao updateProd:prodId cartProd:[prodSub keyValues]];
                        }
                    }
                }
                //重新从服务器获取数据并填充数据库
                MBProgressHUD *lodingView = [DialogUtils showLoadingWithView:self.view];
                [CartDataTool postCartProdsWithParam:[self getCommitParams] success:^(CartInfo *result) {
                    [lodingView hide:YES];
                    if([Utils isBlankString:result.data]){
                        [self updateServerCartInfoToDB];
                    }else{
                        [DialogUtils showTipsWithView:self.view String:result.data];
                    }
                } failure:^(NSError *error) {
                    [lodingView hide:YES];
                    [DialogUtils showTipsWithView:self.view String:@"删除商品失败"];
                }];
            }
        }else{//删除正常商品
            if(TOKEN){//登录状态先删服务器再删本地数据库
                MBProgressHUD *loding = [DialogUtils showLoadingWithView:self.view];
                JXBaseRequest *request = [[JXBaseRequest alloc]init];
                NSDictionary *dic = [request keyValues];
                NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:dic];
                [params setObject:[[_cartInfos[[alertView tag]]infos]prodId] forKey:@"prodId"];
                [CartDataTool deleteCartProdWithParam:params success:^(CartInfo *result) {
                    [loding hide:YES];
                    if([Utils isBlankString:result.data]){
                        JXLog(@"服务器删除商品成功");
                        //2.删除数据库该商品
                        [self deleteDBCartProd:[_alert tag]];
                    }
                } failure:^(NSError *error) {
                    [loding hide:YES];
                }];
                
            }else{//非登录直接删除数据库
                [self deleteDBCartProd:[_alert tag]];
            }
        }
        
    }
}

/**
 *  删除本地数据库商品
 *  @param position 点击的位置cell
 */
-(void)deleteDBCartProd:(NSUInteger)position
{
    BOOL result = [_cartInfoDao deleteProd:[[_cartInfos[position] infos] prodId]];
    if(result){
        JXLog(@"数据库删除商品成功");
        //从数据查询并刷新
        [self queryDBFillData];
    }
}

/**
 *  去逛逛
 */
-(void)scroll
{
    [self.tabBarController setSelectedIndex:1];
}

/**
 *  组织要提交到服务器的参数
 */
-(NSMutableDictionary *)getCommitParams
{
    NSArray *prods = [_cartInfoDao findAllProds];
    
    JXBaseRequest *request = [[JXBaseRequest alloc]init];
    NSDictionary *dic = [request keyValues];
    NSMutableArray *prodArray = [NSMutableArray array];
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:dic];
    for (CartProdSub *prod in prods) {
        NSMutableDictionary *prodDic = [NSMutableDictionary dictionary];
        [prodDic setObject: [prod prodId] forKey:@"prodId"];
        [prodDic setObject:  [prod prodCount] forKey:@"prodCount"];
        [prodArray addObject:prodDic];
    }
    //NSArray转换为Data
    NSData *jsonData =[self dicWithArrayToData:prodArray];
    //Data转换为JSON
    NSString* cartPords = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    [params setObject:cartPords forKey:@"cartPords"];
    return params;
}

/**
 *  去结算
 */
-(void)toAccountWithPostParams
{
    if(TOKEN){//如果已经登录，提交本地数据,跳转到订单页面
        [CartDataTool postCartProdsWithParam:[self getCommitParams] success:^(CartInfo *result) {
            if([Utils isBlankString:result.data]){//购物车数据提交到服务器成功
                JXLog(@"购物车数据提交成功");
                [self getAccountCenterInfo];
            }else{//购物车数据提交到服务器失败
                JXLog(@"购物车数据提交失败");
            }
        } failure:^(NSError *error) {
            
        }];
    }else{//如果未登录，去登录页面
        [self jumpToLogin];
    }
}

/**
 *  跳转到登录
 */
-(void)jumpToLogin
{
    JXNavigationController *nav = [[JXNavigationController alloc]initWithRootViewController:[[JXLoginRegistCheckController alloc]init]];
    [self presentViewController:nav animated:true completion:^{}];
}

/**
 * 获取结算中心需要的信息,去结算
 */
-(void)getAccountCenterInfo
{
    MBProgressHUD *loding = [DialogUtils showLoadingWithView:self.view];
    [CartDataTool getAccountCenterDataWithParam:nil success:^(AddressAndCheckProdInfo *result) {
        [loding hide:YES];
        if([Utils isBlankString:result.data]){//获取结算中心需要的数据成功
            _accountInfo = nil;
            _accountInfo = result;
            //检测本地购物车是否含有过期商品
            [self checkCartInfo:result];
        }
    } failure:^(NSError *error) {
        [loding hide:YES];
    }];
}

/**
 *  校验购物车信息
 *  @param info
 */
-(void)checkCartInfo:(AddressAndCheckProdInfo *)info
{
    //校验过期商品
    [_prodIds removeAllObjects];
    [_prodIds addObjectsFromArray:[info outStockList]];
    //如果有过期的商品就删除,并且给用户提示
    if(_prodIds && _prodIds.count>0){
        _alert = nil;//每次都创建新的alert,并指定tag
        _alert = [[UIAlertView alloc]initWithTitle:@"删除过期的商品?" message:@"" delegate: self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
        //指定是删除过期商品的tag
        [_alert setTag:ISOUTLISTALERT];
        _alert.delegate = self;
        [_alert show]; //显示删除对话框
    }else{
        [self toAccountCenter];
    }
}

/**
 *  跳转到结算中心
 */
-(void)toAccountCenter
{
    [_accountInfo setCurrentPayMode:1];
    [_accountInfo setIsImmediatelyPay:NO];
    JXAccountCenterController *accountCenter = [JXAccountCenterController initWithProdInfo:_accountInfo :ACCOUNT_CENTER_CART_FINISH];
    accountCenter.delegate = self;
    [self.navigationController pushViewController:accountCenter animated:YES];
}

/**
 *  刷新完成，关闭刷新头
 */
-(void)refreshComplete
{
    [self.tableView headerEndRefreshing];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //判断没有数据就不显示表格线，有数据则显示
    if(_cartInfos.count){
        tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    }else{
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _cartInfos.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    JXCartInfoCell *cell = [JXCartInfoCell cellWithTableView:tableView position:indexPath.row];
    [cell setCartInfoFrame:_cartInfos[indexPath.row]];
    cell.prodItemView.calcView.delegate = self;
    cell.prodItemView.delegate = self;
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //处理cell点击效果
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    JXCartInfoFrame *frame = _cartInfos[indexPath.row];
    return frame.cellHeight;
}

-(void)viewDidLayoutSubviews
{
    //改变分割线的样式
    [Utils setSeparatorInsetWithTableView:self.tableView insets:UIEdgeInsetsMake(0, JXPublicInset, 0, 0)];
}

/**
 *  跳转到商品详情
 *
 *  @param position 当前点击的位置
 */
-(void)toProductDetail:(NSInteger)position
{
    JXProdDetailCtl *ctrl = [[JXProdDetailCtl alloc]initWithPordId:[_cartInfos[position] infos].prodMainId];
    [self.navigationController pushViewController:ctrl animated:YES];
}

/**
 *  结算中心关闭的回调
 *
 *  @param type
 *  @param status
 */
-(void)accountCenterFinish:(int)type status:(NSString *)status
{
    if(type == ACCOUNT_CENTER_CART_FINISH){
        [_cartInfoDao deleteAllProds];
        [self toOrderStatusPage:status];
    }
}

/**
 *  结算中心页面关闭,回调跳转至支付状态页面
 *
 *  @param resultCode 状态码
 */
-(void)toOrderStatusPage:(NSString *)resultCode
{
    CartOrderStatusController *ctr = [CartOrderStatusController initWithResultCode:resultCode type:ORDER_STATUS_CART];
    ctr.delegate = self;
    //进入状态页面
    [self.navigationController pushViewController:ctr  animated:YES];
}

/**
 *  订单状态页面关闭,回调跳转至订单列表页
 *
 *  @param type
 */
-(void)orderStatusFinish:(int)type
{
    if(ORDER_STATUS_CART == type){
        [self.navigationController pushViewController:[[JXOrderViewController alloc]init] animated:YES];
    }
}

@end
